package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.jdbc.Null;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


//门票所拥有的属性
@Getter
@Setter
@JsonIgnoreProperties
public class Ticket extends BaseDomain{

    public static final Integer TYPE_NORMAL= 1; //正常
    public static final Integer TYPE_WITHDRAW=0; //下架

    private ScenicSpot scenicSpot;//门票在哪个景点下

    private BigDecimal price=null;//门票价格

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date date;//门票有效期

    private Integer type=TYPE_NORMAL;//门票类型

    public String getTypeName(){
        String msg="正常";
        if(type==TYPE_WITHDRAW){
            msg="下架";
        }
        return msg;
    }

    //进行回显所需要的json
    public String getJson(){
        Map<String,Object> map=new HashMap<>();
        if (scenicSpot != null) {
            map.put("ScenicSpotId",scenicSpot.getId());
            map.put("scenicSpotName",scenicSpot.getScenicSpotName());
        }
        map.put("id",id);
        map.put("type",type);
        map.put("price",price);
        if(date!=null){
            map.put("date", DateUtil.formatDate(date));
        }
        return JSONUtil.toJSONString(map);
    }

}